/* TODO: use a list of available tools to generate buttons on the toolbar
 * instead of the current testing kludges
 * 
 */

/*
 * Whiteboard.java
 *
 * Created on Jan 4, 2012, 2:58:00 PM
 */

package org.amitycs.collabdrawing.gui;

import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import org.amitycs.collabdrawing.Whiteboard;
import org.amitycs.collabdrawing.client.Client;

/**
 *
 * @author joe
 */
public class WhiteboardWindow extends javax.swing.JFrame {

    private Whiteboard whiteboard;

    /** Creates new form Whiteboard */
    public WhiteboardWindow(Whiteboard wb, Client c) {
        whiteboard = wb;
        initComponents();
        ((WhiteboardPanel) wbPanel).setClient(c);
        wbPanel.addMouseListener((MouseListener) wbPanel);
        wbPanel.addMouseMotionListener((MouseMotionListener) wbPanel);

        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        toolbar = new javax.swing.JToolBar();
        penBtn = new javax.swing.JButton();
        lineBtn = new javax.swing.JButton();
        wbPanel = new WhiteboardPanel(whiteboard);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        toolbar.setRollover(true);

        penBtn.setText("Pen");
        penBtn.setFocusable(false);
        penBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        penBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        penBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                penBtnActionPerformed(evt);
            }
        });
        toolbar.add(penBtn);

        lineBtn.setText("Line");
        lineBtn.setFocusable(false);
        lineBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        lineBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        lineBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lineBtnActionPerformed(evt);
            }
        });
        toolbar.add(lineBtn);

        javax.swing.GroupLayout wbPanelLayout = new javax.swing.GroupLayout(wbPanel);
        wbPanel.setLayout(wbPanelLayout);
        wbPanelLayout.setHorizontalGroup(
            wbPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 662, Short.MAX_VALUE)
        );
        wbPanelLayout.setVerticalGroup(
            wbPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 425, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolbar, javax.swing.GroupLayout.DEFAULT_SIZE, 686, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(wbPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(wbPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(toolbar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void lineBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lineBtnActionPerformed
        LineTool lt = new LineTool(whiteboard);
        lt.registerListener((WhiteboardPanel) wbPanel);
        ((WhiteboardPanel) wbPanel).setTool(lt);
    }//GEN-LAST:event_lineBtnActionPerformed

    private void penBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_penBtnActionPerformed
        FreedrawTool ft = new FreedrawTool(whiteboard);
        ft.registerListener((WhiteboardPanel) wbPanel);
        ((WhiteboardPanel) wbPanel).setTool(ft);
    }//GEN-LAST:event_penBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton lineBtn;
    private javax.swing.JButton penBtn;
    private javax.swing.JToolBar toolbar;
    private javax.swing.JPanel wbPanel;
    // End of variables declaration//GEN-END:variables

}
